package com.huel.components;



import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.huel.bean.Btn;
import com.huel.taobaostore.R;

import java.util.List;

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder>{
    private List<Btn> mList;
    static class ViewHolder extends RecyclerView.ViewHolder{
        View myView;
        ImageView imageView;
        TextView title;
        public ViewHolder(View itemView) {
            super(itemView);
            myView = itemView;
            imageView = (ImageView) itemView.findViewById(R.id.iv_image);
            title = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }

    public MyRecyclerViewAdapter(List<Btn> list){
        this.mList = list;
}

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.button_layout,null);
        final ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    //将数据绑定到控件上
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Btn bean = mList.get(position);
        holder.imageView.setBackgroundResource(bean.getImg());
        holder.title.setText(bean.getTitle());
    }
    @Override
    public int getItemCount() {
        return mList.size();
    }

}